
import 'package:flutter_test/flutter_test.dart';
import 'package:sciolto/POJO/Song.dart';
import 'package:sciolto/util/DBController.dart';

void main(){

  group(
    'db',
      (){
        test(
            "测试数据库插入操作",
                () async {
              final con = TableConnector("song");
              Song song = Song("123 - 123.mp3");
              print(song);
              int result1 = await con.defaultInsert(song.toMap());
              print(result1);
              con.close();
              expect(result1, 1);
            }
        );
        test(
            "测试数据库查询操作",
                () async {
              final con = TableConnector("song");
              Song song = Song("123 - 123.mp3");
              print(song);
              List<Map<String, dynamic>> list = await con.defaultQuery('mp3_file_name = ?', [song.mp3FileName]);
              print(list.first['mp3_file_name']);
              con.close();
              expect(list.first['mp3_file_name'], song.mp3FileName);
            }
        );
        test(
            "测试数据库更新操作",
                () async {
              final con = TableConnector("song");
              Song song = Song("123 - 123.mp3");
              print(song);
              int result1 = await con.defaultUpdate(song.toMap(),'mp3_file_name = ?', [song.mp3FileName]);
              print(result1);
              con.close();
              expect(result1, 1);
            }
        );
        test(
            "测试数据库删除操作",
                () async {
              final con = TableConnector("song");
              Song song = Song("123 - 123.mp3");
              print(song);
              int result1 = await con.defaultDelete('mp3_file_name = ?', [song.mp3FileName]);
              print(result1);
              con.close();
              expect(result1, 1);
            }
        );
      }
  );

}